<template>
	<jk-dialog
		v-model="showDialog"
		title="详情-保养项目"
		width="800px"
		:show-content-loading="showLoading"
		append-to-body
		:show-close-btn="true"
		:show-confirm-btn="false"
		:show-cancel-btn="false"
		@on-close="onVisibleChange(false)"
		@on-visible-change="onVisibleChange"
	>
		<el-form ref="ruleForm" :model="ruleForm" label-width="100px" :show-message="false">
			<el-row>
				<el-col :span="12">
					<el-form-item class="margin-bottom-10" label="编号">
						<span class="read-only-2">{{ ruleForm.code }}</span>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item class="margin-bottom-10" label="名称">
						<span class="read-only-2">{{ ruleForm.name }}</span>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item class="margin-bottom-10" label="工序">
						<span class="read-only-2">{{ ruleForm.processName }}</span>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item class="margin-bottom-10" label="保养类别">
						<span class="read-only-2">{{ ruleForm.upkeepTypeName }}</span>
					</el-form-item>
				</el-col>
				<el-col v-if="ruleForm.upkeepTypeCode ? ruleForm.upkeepTypeCode.toUpperCase() === 'RHJY' : false" :span="12">
					<el-form-item class="margin-bottom-10" label="规格">
						<span class="read-only-2">{{ ruleForm.upkeepModelName }}</span>
					</el-form-item>
				</el-col>
				<el-col v-if="ruleForm.upkeepTypeCode ? ruleForm.upkeepTypeCode.toUpperCase() === 'RHJY' : false" :span="12">
					<el-form-item class="margin-bottom-10" label="工具">
						<span class="read-only-2">{{ ruleForm.upkeepToolName }}</span>
					</el-form-item>
				</el-col>
			</el-row>
			<jk-divider-card title="保养周期" icon="el-icon-date" placement="center" class="margin-top-20 margin-bottom-10">
				<el-row>
					<el-col :span="24">
						<el-form-item class="margin-bottom-10" label="周期单位">
							<el-radio-group v-model="ruleForm.cycleUnit" disabled>
								<el-radio-button :label="0">时</el-radio-button>
								<el-radio-button :label="1">天</el-radio-button>
								<el-radio-button :label="2">月</el-radio-button>
								<el-radio-button :label="3">年</el-radio-button>
								<el-radio-button :label="4">产量(米)</el-radio-button>
								<el-radio-button :label="5">产量(公斤)</el-radio-button>
								<el-radio-button :label="6">产量(吨)</el-radio-button>
							</el-radio-group>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item class="margin-bottom-10" label="最小周期">
							<span class="read-only-2">{{ ruleForm.cycleMin }}</span>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item class="margin-bottom-10" label="最大周期">
							<span class="read-only-2">{{ ruleForm.cycleMax }}</span>
						</el-form-item>
					</el-col>
				</el-row>
			</jk-divider-card>
			<el-row>
				<el-col :span="24">
					<el-form-item class="" label="备注">
						<el-input v-model="ruleForm.remark" disabled autosize type="textarea" placeholder="备注" />
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
	</jk-dialog>
</template>

<script>
    import { spinUpkeepItemGet } from '../../../../api/basicData/upkeepItem';

    export default {
        props: {
            dialogState: {
                type: Boolean,
                default: false
            },
            dataId: {
                type: [String, Number],
                default: ''
            }
        },
        data() {
            return {
                showDialog: false,
                showLoading: true,
                ruleForm: {}
            };
        },
        methods: {
            onVisibleChange(e) {
                this.$emit('on-visible-change', e);
                if (!e) {
                    Object.assign(this.$data, this.$options.data());
                    this.$nextTick(() => {
                        this.$refs.ruleForm.resetFields();
                    });
                }
            },
            getDetailRequest() {
                this.showLoading = true;
                return spinUpkeepItemGet({ id: this.dataId }).then(res => {
                    this.showLoading = false;
                    if (res.data.status === 200) {
                        this.ruleForm = res.data.res;
                    }
                });
            }
        },
        watch: {
            dialogState(newVal) {
                this.showDialog = newVal;
                if (newVal) {
                    this.getDetailRequest();
                }
            }
        }
    };
</script>
